package com.kate.mall.product.pool;

import com.kate.mall.product.queue.Request;
import com.kate.mall.product.queue.RequestQueue;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2021/10/22 10:56
 */
@Slf4j
public class GoodsSpecificationThreadPool {
    private ThreadPoolExecutor threadPool =
            new ThreadPoolExecutor(10,1000,200,
                    TimeUnit.MILLISECONDS, new SynchronousQueue<>());
    public void init(){
        log.info("====应用启动，开始初始化请求队列和异步线程池=====");
        RequestQueue requestQueue = RequestQueue.queue();
        for(int i=0;i<10;i++){
            ArrayBlockingQueue<Request> queue = new ArrayBlockingQueue<>(100);
            requestQueue.addQueue(queue);
            threadPool.submit(new GoodsSpecificationThread(queue));
        }

    }
}
